Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip masking non-strings #10

Merged
merged 1 commit into from
Sep 27, 2017
Merged

Conversation

filipefigcorreia
Copy link
Collaborator

When providing an undefined parameter to the masking function (or any non-string for that matter), a TypeError is thrown ("TypeError: Cannot read property 'replace' of undefined"). The changes introduced by this PR will make the function simply return the original parameter when it's not a string.

@@ -44,6 +45,11 @@ describe('maskXml()', () => {
`);
});

it('should skip masking non-strings', () => {
should.not.exist(maskXml(['foo', 'bar'])(undefined));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this (just a readability preference):

[undefined, { biz: 'baz' }].forEach(value => {
  maskXml(['foo', 'bar'])(value).should.eql(value);
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails with a TypeError: Cannot read property 'should' of undefined, but this works:

    [undefined, { biz: 'baz' }].forEach(value => {
      should(maskXml(['foo', 'bar'])(value)).eql(value);
    });

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Included other minor improvements too.

@filipefigcorreia filipefigcorreia force-pushed the enhancement/skip-masking-non-strings branch from 70b8eeb to e86fc35 Compare September 27, 2017 10:04
@@ -44,6 +45,12 @@ describe('maskXml()', () => {
`);
});

it('should skip masking non-strings', () => {
[undefined, { biz: 'baz' }, 42].forEach(nonString => {
should(maskXml(['foo'])(nonString)).equal(nonString);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the syntax <object>.should… when possible please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would also fail with a TypeError: Cannot read property 'should' of undefined

@nunofgs nunofgs merged commit 172d55e into master Sep 27, 2017
@nunofgs nunofgs deleted the enhancement/skip-masking-non-strings branch September 27, 2017 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants